perm filename DSKINT.17D[J17,SYS] blob sn#111579 filedate 1974-07-13 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00017 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00003 00002	BEGIN DSKINT
C00006 00003	HERE IS THE 3330 CODE FOR DIAGNOSTIC LOAD AND WRITE
C00009 00004	ENTER HERE TO DO A TRANSFER.
C00013 00005	DOCHK:	PUSH P,DXW		SAVE A COUPLE OF THINGS
C00019 00006	CADDR	CASWAP
C00025 00007	ICALLA:	SKIPGE TAC,LSTREC		NEED BACKUP?
C00028 00008	ICALLC:	SKIPE D2LUZ
C00030 00009	ESYNC:	MOVEM P,INTPDL
C00035 00010	DSKERR		INTERFACE ERRORS
C00041 00011			DISK ERRORS
C00044 00012			ERROR/USAGE STATISTICS
C00047 00013			ERROR PRINT
C00053 00014	ERROR CLASS DESCRIPTIONS
C00055 00015	ERROR CLASS HANDLERS
C00062 00016	HIGH PRIORITY INTERRUPT CODE (HPIC)
C00065 00017	MORE HPIC
C00067 ENDMK
C⊗;
BEGIN DSKINT
; DEVICE DEPENDENT ROUTINE FOR THE 3330
;THIS ONE RECOVERS FROM ERRORS AS MUCH AS POSSIBLE.

;HUNG COUNT FOR DISK IN SECONDS
↑DHNGCT←←=5		;LETS TRY 5 SECONDS FOR NOW
↑DLHNGCT←←=60		;DIAG LOAD TAKES PRETTY LONG

;BITS FOR CONO/CONI 500: CONDITION MASKS.

;LEFT HALF
DSKNXM←←200000		;NON-EX-MEM
DCHNER←←100000		;DATA CHAIN ERROR
SELERR←←40000		;SELECT ERROR
CPARER←←20		;CORE PARITY ERROR

;RIGHT HALF
PARERR←←400000		;FOR SEPARATE PAR ERR CHECK
↑↑CHDEMP←←200000	;COMMAND HOLD BUFFER EMPTY
IDLE←←100000		;PMP IN IDLE STATE
↑↑UNEND←←40000+PARERR	;UNEND OR PARITY ERROR
↑↑NEWST←←20000		;NEW STATUS BIT FROM PETIT.
CPIACT←←20		;CONI: PI REQUEST UP.

;BITS FOR CONO 504.

CLREND←←4000		;CLEAR UNUSUAL END
↑↑ACTCLR←←400		;CLEAR PI REQUEST
↑↑CNEWST←←200		;CLEAR NEW STATUS FLAG
CLRSTS←←40		;CLEAR STATUS.
↑CLRCHL←←20		;CLEAR COMMAND HOLD LOADED
CRESET←←1		;RESET EVERYTHING.

;STATUS BITS IN CONI PMP (500)

↑↑ATTN←←10000
↑↑STMOD←←4000
↑↑CUEND←←2000
↑↑BUSY←←1000
↑↑CHNEND←←400
↑↑DEVEND←←200
↑↑UCHK←←100
↑↑UXCPTN←←40

;THE FOLLOWING BITS ARE FOUND IN THE FIRST 2 SENSE BYTES
BITCL0←←155		;CLASS 0 BITS
CMDRJT←←100000		;COMMAND REJECT IS SPECIAL
BITCL1←←20000		;CLASS 1 BITS
BITCL2←←4000		;CLASS 2 BITS
BITCL4←←2000		;CLASS 4 BITS
BITCL5←←40002		;CLASS 5 BITS
WRTINH←←2		;WRITE INHIBITED
PERM←←200		;PERMANENT ERROR
BITEQU←←10000		;EQUIPMENT CHECK

ERRUSE←←20		;SENSE BYTE 2, ERROR-USAGE DATA PRESENT

;THESE ARE FOUND IN SENSE BYTE 7
SKCHK←←32		;SEEK CHECK
SKINCP←←33		;SEEK INCOMPLETE
RTYABT←←6		;RETRY ABORTED
DWERR←←320		;DIAGNOSTIC WRITE CONTROL BIT ERROR
DVERR←←100		;INVALID DATA ARG (PROBABLY DIAG. LOAD)
;HERE IS THE 3330 CODE FOR DIAGNOSTIC LOAD AND WRITE
↑WLDIAG:MOVEM 17,DSKACS+17
	MOVEI 17,DSKACS
	BLT 17,DSKACS+16
	MOVEM IOS,DEVIOS(DDB)
	SETZ TAC,
	DPB TAC,[POINT 3,TSTXOR,11]		;SO WE DON'T GET ASYNC INT'S
	MOVE TAC,DXC
	MOVEI TAC,DLHNGCT			;DIAGS TAKE QUITE A WHILE
	MOVEM TAC,DHNGST
	MOVEM TAC,DSKHNG
	SETOM DSKACT				;FLAG DISK ACTIVE!
	SETOM ERRCMD				;TELL THEM WHO IT IS
	PUSHJ P,ERRCLR				;CLEAR ERROR COUNTS
WLRTRY:	CONO PMP,NEWST!UNEND!10!DSKCHN
	CONO IBM,CNEWST!CLREND!ACTCLR		;COME HERE TO TRY AGAIN
	MOVE TAC,DXC
	TRNN TAC,DWRITE				;THIS TELLS US IF THIS IS
	JRST LDIAG1				;A LOAD OR WRITE
	DATAO PMP,[FILMSK]
	DATAO IBM,MSKCMD			;SET FILE MASK COMMAND
	PUSHJ P,ISYNC
	JRST WLRTRY
	JRST WLERR
	DATAO PMP,DXS				;WRITE, ADDRESS OF DIAGNOSTIC
	DATAO IBM,DWCMD				;IS IN DXS
	JRST WLWAIT

LDIAG1:	CONO IBM,ACTCLR				;CLEAR ACTIVE
	DATAO PMP,[DXS]				;POINT TO ADDRESS BYTE
	DATAO IBM,DLCMD
WLWAIT:	PUSHJ P,ISYNC
	JRST WLRTRY
	JRST WLERR
	MOVE TAC,PMPCNI
	TRNN TAC,DEVEND
	JRST WLWAIT
	CONO IBM,ACTCLR
	DATAO PMP,DXW
	DATAO IBM,RD1CMD
	PUSHJ P,ISYNC
	JRST WLRTRY
	JRST WLERR
	JRST NOLUZ				;RETORE ACS, AND LEAVE

WLERR:	PUSHJ P,DSKERR
	JRST WLRTRY
	JRST NOLUZ
;ENTER HERE TO DO A TRANSFER.

↑GO2314:MOVEM 17,DSKACS+17
	MOVEI 17,DSKACS
	BLT 17,DSKACS+16
	MOVEM IOS,DEVIOS(DEVDAT)
	AOS DSKOPS		;COUNT TOTAL DSK OPS.
	SKIPLE TAC,DXJ		;GET JOB NUMBER OF USER
	AOS DSKOPS(TAC)		;COUNT A DISK ACCESS FOR THIS USER
	SKIPE DXS		;NOT ON SATOP
	PUSHJ P,CSATID		;CHECK SATID (ROUTINE IS IN DSKSER)
	SETOM DSKACT		;FLAG DISK ACTIVE NOW!
	MOVEI TAC,DHNGCT
	MOVEM TAC,DHNGST
	MOVEM TAC,DSKHNG	;ENABLE HANG CODE
	MOVE TAC,DXC
	TRNE TAC,100		;WRITE OP?
	SKIPG TAC,DXS		;AND FILE OP
	JRST NOCHK		;NO
	MOVE TAC1,DSKACS+DDB
	TRNN TAC,77		;RECORD 0?
	SKIPGE DDLOC(TAC1)	;AND NOT GOD?
	JRST NOCHK		;NO
	PUSHJ P,DOCHK		;YES, TO ALL OF THESE, DO OVERWRITE CHECK!
	JRST NOLUZ		;BLEW UP COMPLETELY!
NOCHK:	PUSHJ P,CADDR		;DO ALL THE SETUP CRUD
	JRST NOLUZ		;ILL ADDR
	SETOM DSKACT		;SET DISK ACTIVE FLAG
	MOVEI TAC,DHNGCT
	MOVEM TAC,DHNGST
	MOVEM TAC,DSKHNG
	PUSHJ P,ICALL		;CALL D2CHN
	SKIPN D2LUZ
	JRST NOLUZ
	MOVE TAC,DSKACS+DDB		;GET DDB ADDRESS
	MOVEI TAC1,IODERR	;GIVE ERROR BIT FOR ILLEGAL WRAP
	IORM TAC1,DEVIOS(TAC)
NOLUZ:	SETZM DSKACT		;CLEAR DISK ACTIVE FLAG
	SETZM DSKHNG		;TELL DEVCHK NOT ACTIVE
	CONO PMP,NEWST!UNEND!10!DSKCHN
	CONO IBM,CNEWST!CLREND!ACTCLR
	CONO PI,D2OFF		;DEACTIVATE HIGH PRIORITY CHANNEL
	SKIPE DXS		;IF NOT SAT TABLE,
	PUSHJ P,CSATID		;CHECK SATID AGAIN (ROUTINE IS IN DSKSER)
	MOVE TAC,STAC		;RESTORE THE SAVED ACS.
	MOVE TAC1,STAC1
	MOVE P,SAVP
	MOVE AC3,SAC3
	MOVE DAT,SDAT
	JSR DSKSV		;NOW SAVE THEM ALL.
	POP P,INTRTN		;SET DISMISS ADDR.
	MOVSI 17,DSKACS		;NOW RESTORE RAS'S ACS.
	BLT 17,17
	MOVE IOS,DEVIOS(DEVDAT)	;GET CURRENT STATUS.
	POPJ P,

DOCHK:	PUSH P,DXW		;SAVE A COUPLE OF THINGS
	PUSH P,DXC
	MOVE TAC,[XWD -SECSIZ,QBUF]
	MOVEM TAC,DXW
	MOVEI TAC,DSKCHN
	MOVEM TAC,DXC
	PUSHJ P,CADDR		;SETUP OVERWRITE CHECK ADDRESS
	JRST [	POP P,DXC
		POP P,DXW
		POPJ P,]	;LOSE BIG, ILLEGAL ADDRESS
	POP P,DXC
	POP P,DXW
	SKIPG DSKLRN		;MAKE SURE WE MUST CHECK
	JRST CPOPJ1		;NOT FILE OP AFTER ALL, SAY CHECK DONE!
	PUSHJ P,ICALL		;READ RETRIEVAL IN
	MOVE TAC1,DSKACS+DDB
	MOVEI TAC,IODERR!IODTER
	SKIPE D2LUZ		;ANY GROSS ERRORS?
	IORM TAC,DEVIOS(TAC1)	;YES, SET ERROR BITS
	TDNE TAC,DEVIOS(TAC1)	;NOW TEST FOR ERRORS
	POPJ P,			;YES, GO AWAY NOW
	MOVE TAC,SATID+SATTAB	;GET NAME OF CURRENT GENERATION OF FILES.
	CAMN TAC,QBUF+DSATID-DSKDAT	;IS BLOCK WE'RE WRITING ON CURRENT ?
	SKIPN AC3,QBUF		;FILENAME OF 0 MEANS NOT IN USE.
	JRST CPOPJ1		;THE BLOCK WE'RE WRITING ON IS NOT IN USE.
	MOVE TAC,QBUF+1		;GET EXTENSION.
	XOR TAC,FILEXT(TAC1)	;TAC1 POINTS AT DDB FOR CURRENT OP.
	CAMN AC3,FILNAM(TAC1)
	TLNE TAC,-1
	SKIPN QBUF+3		;IF PPN IS 0, OR IF
	JRST CPOPJ1		;SAME FILENAME AND EXTENSION. WRITE IS OK.
DSKQK1:	PUSH P,TEM
	HRRZ TEM,DXW		;THIS POINTS TO THE RETRIEVAL WE ARE REWRITING
	MOVE TAC,QBUF+3		;CHECK PPN
	CAMN AC3,(TEM)		;SAME FILNAME?
	CAME TAC,3(TEM)		;AND PPN?
	JRST DSKQKP		;NO
	MOVE TAC,QBUF+1		;EXT
	XOR TAC,1(TEM)
	TLNE TAC,-1
	JRST DSKQKP
	POP P,TEM
	JRST CPOPJ1

DSKQKP:	POP P,TEM
DSKQK2:	CAMN AC3,SRCNAM(TAC1)	;OR PERHAPS RENAMING THE FILE ?
	JRST CPOPJ1		;NOTHING CAN GO WRONGWRONGWRONGWRON
	HRRZ TAC,DXW		;GET STARTING ADDR. OF XFER.
	SKIPL DDLOC(TAC1)	;IS IT (A) GOD ?
	CAIN TAC,SATTAB		;IF WE ARE WRITING OUT THE SAT TABLE,
	JRST CPOPJ1		;...THEN ALL IS WELL (?)
	PUSHACS
	PUSHJ P,DISDATE
	MOVE UUO,DSKACS+DDB
	PUSHJ P,DISERR
	[ASCIZ/OVERWRITE CHECK,  LR = /]
	DISARG LOC,DSKLRN
	[ASCIZ/
WRITING FILE   /]
	DISARG SIX,FILNAM(UUO)
	[ASCIZ/./]
	DISARG SIX,FILEXT(UUO)
	[ASCIZ/[/]
	DISARG SIX,FILPPN(UUO)
	[ASCIZ/]  DDLOC = /]
	DISARG LOC,DDLOC(UUO)
	[ASCIZ/
ON TOP OF FILE /]
	DISARG SIX,QBUF-DSKDAT+DDNAM
	[ASCIZ/./]
	DISARG SIX,QBUF-DSKDAT+DDEXT
	[ASCIZ/[/]
	DISARG SIX,QBUF-DSKDAT+DDPPN
	[ASCIZ/]  DDLOC = /]
	DISARG LOC,QBUF-DSKDAT+DDLOC
	[ASCIZ/


/]
	-1
	SKIPN DEBMOD
	JRST .+3
	SETOM DISFLAG
	PUSHJ P,DISFLUSH
	POPACS
	SKIPE DEBMOD
	PUSHJ P,DDTCALL
NOOSTP:	AOS DSKOVC		;COUNT OVERWRITE ATTEMPTS.
	MOVSI TAC,HDRDIF!PNTDIF	;INDICATE THAT RETRIEVAL MUST BE SPREAD AGAIN.
	IORM TAC,DEVIOS(TAC1)
	MOVE AC3,TAC1		;SAVE PTR. TO TABLE OF BLOCK LOCATIONS IN DDB.
	PUSH P,AC1
	PUSH P,AC2
	PUSHJ P,IASNBK		;ASSIGN A NEW BLOCK TO REPLACE THE ONE WE DON'T
				; WANT TO CLOBBER.
	MOVE TAC1,[POINT 18,DPTR(AC3)]	;BYTE PTR. TO TABLE OF BLOCKS IN FILE.
	MOVEI AC2,40		;LENGTH OF TABLE FOR ONE 32K GROUP OF FILE.
	ILDB AC1,TAC1		;SEARCH FOR BLOCK WE WERE WRITING ON.
	CAME AC1,DSKLRN		;DSKLRN IS BLOCK WE WERE WRITING ON.
	SOJG AC2,.-2

	JUMPG AC2,DSKQK3	;DID WE FIND BLOCK IN TABLE ?
	POP P,AC2
	POP P,AC1
	JRST DSKQY
DSKQK3:	DPB TAC,TAC1		;REPLACE OLD BLOCK WITH NEW ONE IN TABLE.
	POP P,AC2
	POP P,AC1
	CAME TAC1,[POINT 18,DPTR(AC3),17]	;WAS IT FIRST BLOCK OF THIS GROUP ?
	JRST DSKQZ		;NO.
	MOVSI TAC1,NTRUFD	;YES. MAKE CLOSE UPDATE UFD ENTRY.
	IORM TAC1,DEVIOS(AC3)
	MOVEI TAC1,1		;YES. IS THIS GROUP 1 OF THE FILE ?
	CAME TAC1,DGRP1R(AC3)
	JRST DSKQY	
	HRRZM TAC,FILLOC(AC3)	;YES. NEW BLOCK IS NEW LOCATION OF FILE.
	HRRZM TAC,DDLOC(AC3)	;ALSO PUT IT HERE.
	JRST DSKQZ
DSKQY:	MOVEI TAC1,IODERR	;NO. THERE IS NOTHING REASONABLE WE CAN DO.
	IORM TAC1,DEVIOS(AC3)	;GIVE THE LOSER LOSSAGE BIT.
	POPJ P,			;SKIP RETURN TO DSKINT.
DSKQZ:	PUSHJ P,BK2SEC		;NOW UPDATE DISK ADDR. OF CURRENT XFER TO BE NEW BLOCK.
	MOVEM TAC,DXS
	JRST DOCHK
;CADDR	CASWAP

CASWAP:	TLZ TAC,400000		;CLEAR SWAP OP BIT!
	LSH TAC,-14		;GET JOB NUMBER(WE HOPE)!
	IMULI TAC,<CAT(NTRK,\<NPACKS-1>)/LJOBN>	;DIVIDE SWAPPING PACK AMONG
						;ALL POSSIBLE JOBS
	MOVE TAC1,SWPDDB
	ADD TAC,UDPOFF(TAC1)	;GET OFFSET FROM DDB
	HRROM TAC,DSKLRN	;DISABLE MRKBAD
	MOVSI TAC1,(<BYTE(8)1>)	;WRAP TO RECORD 1 ON 3330
	MOVEM TAC1,XWRAP
	MOVEI TAC1,1		;AND START AT RECORD 1
	JRST CDX3		;TAC=TRACK NUMBER, TAC1= RECORD NUMBER = 1

CADDR1:	MOVE AC3,DXC
	TRNE AC3,100		;SAT TABLE, IS IT WRITE?
	JUMPN TAC1,CDX4		;YES, BETTER BE RECORD 0
	SETOM DSKLRN		;DISABLE MRKBAD
	JRST CDX3S		;TAC=0, TAC1=RECORD NUMBER (=0 FOR WRITE)

;TAC HAS RELATIVE BLOCK NUMBER
CAXTRA:	IDIVI TAC,100		;TAC ← REL BLOCK #, TAC1 ← REC
	CAIL TAC,NXTRA0*TRKCYL*BKPTRK
	JRST CDX4		;WE DON'T HAVE THAT MANY EXTRA TRACKS
IFG BKPTRK-1,<
	MOVEI AC3,(TAC1)
	IDIVI TAC,BKPTRK
	IMULI TAC1,CRMAX
	ADDI TAC1,(AC3)
>
	CAIL TAC1,RCPTRK
	JRST CDX4		;RECORD NUMBER TOO BIG
	SETZB AC3,XWRAP		;PACK 0, WRAP AROUND TO RECORD 0
	SETOM DSKLRN		;DISABLE MRKBAD
	ADDI TAC,NTRK0		;OFFSET TO END OF PACK 0
	JRST CDXE

CADDR:	MOVE TAC,DXW
	HRLZ TAC1,DXC
	TLNN TAC1,100		;READ OR RIGHT?
	TROA TAC1,-1		;FLAG READ
	SUB TAC,[1,,0]		;CAUSES CHNL TO NOT STOP XFER TOO SOON
	MOVEM TAC,XWCMA
	MOVE TAC,WCMD(TAC1)	;PICKUP COMMAND
	MOVEM TAC,XCMD
	MOVE TAC,ENDTAB(TAC1)	;PICKUP INSTRUCTION FOR ENDING TEST ON WC
	MOVEM TAC,ENDTST	;AND STUFF IT AWAY
	MOVE TAC,[JSR D2INT]	;MAKE SURE D2CHN KNOWS WHERE TO GO
	MOVEM TAC,140+2*D2CHN
	SKIPGE TAC,DXS
	JRST CASWAP		;SIGN BIT MEANS SWAP OP, WITH SHIFTED JOB NUMBER
	TLZE TAC,200000
	JRST CAXTRA		;200000 BIT MEANS XTRA CYL PACK 0 OP
	IDIVI TAC,100			;TRACK INTO TAC, RECORD INTO TAC1
	JUMPE TAC,CADDR1		;JUMP IF SAT TABLE OPERATION
	MOVEM TAC,DSKLRN		;SAVE LOGICAL BLOCK NUMBER IN CASE OF ERROR
	CAILE TAC,LSTBIT		;FILE OP?
	HRROS DSKLRN			;NO, DISABLE MRKBAD
IFG BKPTRK*NSATBK-1,<
	ADDI TAC,BKPTRK*NSATBK-1	;LEAVE ENOUGH ROOM FOR SAT TABLE
>
IFG BKPTRK-1,<				;ASSEMBLE CODE FOR MULTIPLE BLOCKS/TRACK
	MOVEI AC3,(TAC1)
	IDIVI TAC,BKPTRK		;DIVIDE BY BLOCKS/TRACKS
	IMULI TAC1,CRMAX		;TIMES RECORDS/BLOCK (INCL RETRIEVAL)
	ADDI TAC1,(AC3)			;CALC REAL DISK RECORD NUMBER
>
CDX3S:	SETZM XWRAP			;WRAP TO RECORD ZERO ON OVERFLOW
CDX3:	CAIGE TAC1,RCPTRK		;RECORD OK?
	CAILE TAC,LSTTRK		;OFF END OF WORLD?
	JRST CDX4			;LOSER

	MOVSI AC3,-NPACKS		;SEARCH FOR THE PACK CONTAINING THIS TRACK
CDXL:	CAMLE TAC,PACKAD(AC3)
	AOBJN AC3,CDXL
	JUMPGE AC3,CDX4			;THIS IS TOO HORRIBLE TO THINK ABOUT.
	SUB TAC,PACKAD-1(AC3)
	SUBI TAC,1			;AC3=PACK, TAC=TRACK NUMBER ON THAT PACK
CDXE:	ROT TAC1,-8			;PUT RECORD BYTE IN LEFT BYTE
	MOVEM TAC1,SCDAT+1		;STUFF AWAY
	IDIVI TAC,TRKCYL		;STRIP OFF HEAD NUMBER
	DPB TAC1,[POINT 8,SKDAT+1,15]	;STUFF HEAD NUMBER
	DPB TAC1,[POINT 16,SCDAT,31]
	DPB TAC,[POINT 16,SKDAT,31]	;STUFF CYLINDER NUMBER
	DPB TAC,[POINT 16,SCDAT,15]
	DPB AC3,[POINT 3,SKCMD,21]	;STUFF PACK NUMBER
	DPB AC3,[POINT 3,SCCMD,21]
	DPB AC3,[POINT 3,XCMD,21]
	DPB AC3,[POINT 3,NOPCMD,21]
	DPB AC3,[POINT 3,SNSCMD,21]
	DPB AC3,[POINT 3,RDHACM,21]
	DPB AC3,[POINT 3,RCALCM,21]
	DPB AC3,[POINT 3,TSTXOR,11]
	SETZM LWCMA			;NO LAST ERROR YET!
	SETZM LSTOP
	SETOM LSTREC			;FOR SAFETY, FLAG XWCMA & SCDAT ARE NEXT OP TO DO
	JRST CPOPJ1

CDX4:	MOVEM TAC,TYPANY	;STUFF AWAY HERE FOR NOW
	MOVEM TAC1,DSKFLG
	PUSHACS
	PUSHJ P,DISERR
	[ASCIZ/ILLEGAL DISK ADDRESS.  DXS = /]
	DISARG OCT,DXS
	[ASCIZ/
LR = /]
	DISARG LOC,TYPANY
	[ASCIZ/  REC = /]
	DISARG LOC,DSKFLG
	[ASCIZ/
JOB = /]
	-1
	HRRZ J,DXJ
	JUMPE J,.+2
	PUSHJ P,DISJOB
	SKIPL DXS
	JRST NOGOD
	PUSHJ P,DISMES
	ASCIZ/  SWAP OP!/
NOGOD:	PUSHJ P,DISMES
	ASCIZ/

/
	POPACS
	MOVE TAC,DSKACS+DDB
	MOVEI TAC1,IODERR
	IORM TAC1,DEVIOS(TAC)
	POPJ P,

ICALLA:	SKIPGE TAC,LSTREC		;NEED BACKUP?
	JRST ICALLN			;NO, XWCMA & SCDAT ARE NEXT OP TO DO
	SETOM LSTREC			;NOTE WE ARE BACKED UP
	EXCH TAC,SCDAT+1		;BACKUP RECORD
	CAMLE TAC,SCDAT+1		;DO WE BACK UP A TRACK?
	JRST TOK			;NO
	MOVSI TAC,(<BYTE(16)<-1>>)	;GET SOMETHING TO DECREMENT HEAD ADDR
	ADDB TAC,SKDAT+1		;DECREMENT HEAD ADDR
	JUMPGE TAC,COK			;CYLINDER OK?
	MOVNI TAC,1⊗4
	ADDB TAC,SKDAT			;DECREMENT CYLINDER
	MOVSI TAC,(<BYTE(16)TRKCYL-1>)
	MOVEM TAC,SKDAT+1		;SET HEAD TO LAST TRACK OF CYLINDER
COK:	HLRZ TAC,SKDAT+1		;NOW COMPUTE SCDAT FROM SKDAT
	LSH TAC,4
	HRL TAC,SKDAT
	LSH TAC,-2
	MOVEM TAC,SCDAT			;STORE UPDATED SEARCH LOC
TOK:	LDB TAC,[POINT 8,SCDAT+1,7]	;USE RECORD NUMBER,
	MOVN TAC,RCLTAB(TAC)		;TO GET VALUE TO,
	ADDM TAC,XWCMA			;BACKUP XWCMA BY
ICALLN:	HRRZ TAC,D2X			;GET LOC OF LAST JSR +1
	LDB TAC,[POINT 4,-1(TAC),12]	;GET CODE FROM AC FIELD OF JSR
	MOVE TAC1,XCMD			;SET FOR DSKERR CODE AS LAST OP IN PROGRESS
	TRNE TAC1,1			;WRITE OP?
	CAIE TAC,2			;YES, IF LAST OP IN PROGRESS WAS READ OR WRITE,
	CAIA
	ADDI TAC,1			;SET CODE FOR WRITE
	MOVEM TAC,ERRCMD
	MOVE TAC1,XWCMA			;GET ERROR WCMA
	CAMN TAC,LSTOP			;SAME COMMAND IN ERROR?
	CAME TAC1,LWCMA			;AND SAME WCMA
	CAIA
	POPJ P,				;NO, DON'T RESET COUNTS
	MOVEM TAC,LSTOP
	MOVEM TAC1,LWCMA		;REMEMBER LAST ERROR
ERRCLR:					;ENTER HERE TO CLEAR ERROR COUNTS
FOR @!X←0,4<
	SETZM ERRCL!X>
	SETOM SHADPE
	POPJ P,
ICALLC:	SKIPE D2LUZ
	POPJ P,				;EOD, RETURN NOW!!!!!
ICALL:	SETZM D2DONE			;NOT SUCCESSFUL YET!
	SETZM D2LUZ			;HAVEN'T LOST YET
	SETOM CT			;MAKE SURE WE DON'T INTERPRET RANDOM ERRORS AS LOSING SEARCHES
	MOVEI TAC,D2IGO			;START D2CHN HERE
	MOVEM TAC,D2X
	CONO PI,D2ON			;TURN ON HIGH PRIORITY CHANNEL
	CONO IBM,CNEWST!CLREND!CLRCHL	;MAKE SURE AN INT WILL HAPPEN
	CONO PMP,NEWST!UNEND!CHDEMP!10!D2CHN	;DOWN TO CHANNEL 2
	PUSHJ P,ESYNC			;WAIT TILL DONE OR ERROR
	JRST ICALLB			;RETRY, START D2CHN OVER
	AOSN D2DONE			;SUCCESSFUL OP?
	POPJ P,				;YES, JUST RETURN
	PUSHJ P,ICALLA			;GRONK PARMS
	PUSHJ P,DSKERR			;ERROR, CALL ROUTINE
	JRST ICALLC			;TRY AGAIN
	POPJ P,				;QUIT, ERRORS ALREADY POSTED

ICALLB:	PUSHJ P,ICALLA
	JRST ICALLC

ISYNC:	PUSHJ P,ESYNC			;WAIT FOR OP TO HAPPEN
	POPJ P,				;TRY AGAIN RETURN
	AOS (P)				;AT LEAST ONE SKIP
	MOVE TAC,PMPCNI			;GET CONI BITS
	TRNE TAC,UNEND!ATTN!UXCPTN!CUEND!STMOD;ANY ERRORS?
	POPJ P,				;YES, RETURN
	JRST CPOPJ1			;NO ERRORS
ESYNC:	MOVEM P,INTPDL
	SETZM HNGFLG			;ALWAYS CLEAR HUNG FLAG HERE!
	JRST @INTRTN

↑IXINT:	MOVEM TAC,STAC			;ENTER HERE FROM LOW-PRIORITY CHANNEL
	MOVEM TAC1,STAC1
	MOVEM AC3,SAC3
	MOVEM DAT,SDAT
	MOVEM P,SAVP
	MOVE P,INTPDL
	MOVEI TAC,IXINT2
	MOVEM TAC,INTRTN
	CONI PMP,TAC
	MOVEM TAC,PMPCNI
	TRNE TAC,UNEND			;UNUSUAL END?
	CONO IBM,CLRCHL			;YES, CLEAR ANY WAITING COMMANDS
	CONO IBM,CNEWST!CLREND		;CLEAR NEWST AND UNEND WHEN STATUS GOBBLED
	SKIPN DSKACT			;IS DISK ACTIVE AT ALL?
	JRST ASYNC			;NO
	MOVE TAC1,DHNGST		;THIS IS DISK HUNG TIME COUNT IN SECONDS
	MOVEM TAC1,DSKHNG		;THIS IS WHERE IT IS COUNTED DOWN
	TRNN TAC,NEWST			;IS THIS DEVICE STATUS?
	JRST CPOPJ1			;NO, MUST BE END OF TRANSFER, RETURN
	TRNE TAC,CUEND			;CUEND ALONE?
	POPJ P,				;INDICATE TRY AGAIN
	TRC TAC,STMOD!BUSY
	TRCN TAC,STMOD!BUSY		;CU BUSY?
	JRST CKBUSY			;YES
	XOR TAC,TSTXOR
	TLNN TAC,37700			;WRONG ADDRESS?
	JRST CHKRTY			;NO, CHECK RETRY
	JRST ASYNC0			;USE STACK WE HAVE

ASYNC:	MOVE TAC,STAC			;RESTORE STATE OF AC'S
 	MOVE TAC1,STAC1
	MOVE AC3,SAC3
	MOVE DAT,SDAT
	MOVE P,SAVP
	JSR DSKSAV			;NOW SAVE THEM ALL!
ASYNC0:	CONO IBM,CLRCHL
	PUSHACS
	PUSHJ P,DISDATE
	LDB TAC,[POINT 8,PMPCNI,30]
	CAIN TAC,DEVEND⊗-5		;JUST DEVEND?
	JRST DEVRDY			;YES, SHORT MES.
	PUSHJ P,DISMES
	ASCIZ/ASYNCHRONOUS DISK DEVICE INTERRUPT.
/
	JRST SWAIT

DEVRDY:	PUSHJ P,DISMES
	ASCIZ/DISK PACK /
	LDB TAC,[POINT 3,PMPCNI,11]
	PUSHJ P,DISLOC
	PUSHJ P,DISMES
	ASCIZ/ ON LINE.
/
SWAIT:	PUSHJ P,DISERR
	[ASCIZ/CONI BITS = /]
	DISARG OCT,PMPCNI
	[ASCIZ/
/]
	-1
	CONSO PMP,NEWST
	JRST SDONE
	CONI PMP,PMPCNI
	CONO IBM,CNEWST!CLREND
	JRST SWAIT
SDONE:	SKIPN DSKACT			;ARE WE ACTIVE?
	JRST SDONE0
	PUSHJ P,DISMES
	ASCIZ/DISK ACTIVE, PACK = /
	LDB TAC,[POINT 3,TSTXOR,11]
	PUSHJ P,DISLOC
SDONE0:	PUSHJ P,DISMES
	ASCIZ/

/
	POPACS
	PUSHJ P,BLAST			;WAIT FOR IDLE THEN RESET
	SKIPE DSKACT			;IS DISK REALLY ACTIVE?
	JRST UCHKTS			;GIVE TRY AGAIN RETURN!
	CONO PMP,NEWST!UNEND!10!DSKCHN	;WE AREN'T ACTIVE, SET TO QUIET STATE
	CONO IBM,ACTCLR
	POPJ P,				;THIS WILL RESTORE AC'S AND JEN

UCHKTS:	MOVE TAC,PMPCNI
	TRNN TAC,STMOD			;IF STATUS MODIFIER
	TRNN TAC,UCHK			;OR NOT UNIT CHECK
	POPJ P,				;THEN GIVE TRY AGAIN RETURN
	SETZM D2DONE			;MAKE SURE ERROR ROUTINE IS CALLED
	JRST CPOPJ1			;GIVE DONE RETURN

IXINT2:	MOVE TAC,STAC
	MOVE TAC1,STAC1
	MOVE AC3,SAC3
	MOVE DAT,SDAT
	MOVE P,SAVP
	JEN @DSKCHL

CKBUSY:	SETZM D2DONE			;MAKE SURE WE DON'T LOOK DONE!
;	EXCH DDB,DXB
;	LDB TAC1,PDVTIM			;MAKE SURE LOSER DOSEN'T HANG
;	DPB TAC1,PDVCNT
;	EXCH DDB,DXB
	TRNE TAC,CUEND			;CUEND ALREADY?
	POPJ P,				;TRY AGAIN
WAIT:	CONO PMP,NEWST!UNEND!10!DSKCHN
	CONO IBM,ACTCLR
	JRST IXINT2			;WAIT FOR CUEND

CHKRTY:	TRC TAC,STMOD!UCHK
	TRCE TAC,STMOD!UCHK
	JRST CPOPJ1
	SETZM D2DONE
	TRNN TAC,DEVEND
	JRST WAIT
	JRST CPOPJ1
;DSKERR		INTERFACE ERRORS
DSKERR:	PUSHACS
	CONO IBM,CLRCHL
	CONO IBM,CNEWST!CLREND		;FROM HERE ON CHANNEL SHOULD BE IDLE
	SETZM TYPANY			;NO TYPE OUT YET
	SETZM SNSTYP
	SETZM CSTOP
	SETZM DEATH
	SETZM HAFLAG
	SETZM DSKFLG			;HAVEN'T FOUND OUT WHY YET
	MOVE UUO,PMPCNI			;GET ERROR BITS
	MOVEM UUO,CNISAV		;AND SAVE THEM IN A SAFE PLACE
	DATAI IBM,XDSKMA			;GET CURRENT MA
	TLNN UUO,SELERR			;IF SELECT ERROR, CHECK IF OFF LINE
	JRST NOSEL			;NO
	CONO IBM,CRESET			;EXTRA RESET FOR SELERR
	PUSHJ P,BLAST
	POPACS
	CONO IBM,CNEWST!CLREND!ACTCLR
	CONO PMP,NEWST!UNEND!10!DSKCHN
	DATAO IBM,NOPCMD
	PUSHJ P,ISYNC
	JRST .-2			;TRY AGAIN?
	JFCL				;SORT OF IGNORE ERROR RETURN
	PUSHACS				;GET ACS BACK(FORTH?)
	MOVE TAC,PMPCNI
	TLNN TAC,SELERR			;STILL SELECT ERROR?
	JRST NOSELA
	CONO IBM,CRESET
	PUSHJ P,BLAST
	PUSHJ P,DISMES
	ASCIZ/I THINK I'M OFF LINE!
/
	AOS CSTOP
NOSELA:	PUSHJ P,ERROR1
	MOVE UUO,CNISAV
NOSEL:	SKIPGE CT			;TOO MANY LOSING SEARCHES?
	JRST NOLSRC			;NO
	PUSHJ P,DISMES
	ASCIZ/TOO MANY LOSING SEARCHES.
/
	AOS TYPANY
	PUSHJ P,ERROR0
	HLRZ TAC,SKDAT+1		;THIS IS A BUG TRAP!!!!*******
	LSH TAC,4
	HRL TAC,SKDAT
	LSH TAC,-2
	EXCH TAC,SCDAT
	CAMN TAC,SCDAT
	JRST NOLSRC
	PUSH P,TAC
	PUSHJ P,DISERR
	[ASCIZ/SCDAT WAS CLOBBERED!
OLD SCDAT = /]
	DISARG OCT,<-1(P)>
	[ASCIZ/
NEW SCDAT = /]
	DISARG OCT,SCDAT
	[ASCIZ/
/]
	-1
	POP P,TAC			;END BUG TRAP!!!!*********
NOLSRC:	SKIPN HNGFLG			;DOES SOMEONE THINK WE'RE HUNG?
	JRST NOHUNG			;NO
	AOS DSKFLG
	AOS TYPANY
	PUSHJ P,DISMES
	ASCIZ/HUNG TIMEOUT!
/
NOHUNG:	TDNE UUO,[DCHNER,,ATTN!BUSY!UXCPTN]	;DATA CHAIN ERROR?
	PUSHJ P,ERROR0			;CLASS 0 ERROR
	TLNN UUO,DSKNXM			;NXM?
	JRST NONXM
	PUSHJ P,DISERR
	[ASCIZ/DISK NON-EX-MEM.
DISK MA = /]
	DISARG LOC,XDSKMA
	[ASCIZ/
/]
	-1
	PUSHJ P,ERROR1			;ERROR, CLASS ONE
	AOS TYPANY			;ALWAYS TYPE
NONXM:	TLNN UUO,CPARER			;CORE PARITY ERROR?
	JRST BPAR
	MOVE TAC,XDSKMA
	CAMG TAC,RMEMSIZ
	CAIGE TAC,20
	AOSE SHADPE
	JRST REALPE	;AW, LOOK, WE'VE BEEN ALL THROUGH THIS BEFORE
	PUSHJ P,ZSHAD
	JFCL		;ZSHAD SKIPS IF NO FAST ACS
	AOS DSKFLG
	JRST NOPAR	;IGNORE IT FOR NOW
REALPE:	PUSHJ P,DISERR
	[ASCIZ/CORE TO DISK PARITY ERROR.
DISK MA = /]
	DISARG LOC,XDSKMA
	[ASCIZ/
/]
	-1
	SKIPA TAC,RMEMSIZ		;LOOK AT ALL OF CORE FOR ERROR
	SKIP (TAC)
	SOJGE TAC,.-1
	AOS TYPANY			;TELL THEM WHO LOST
BPAR:	TRNN UUO,PARERR			;PARITY ERROR
	JRST NOPAR			;NO
	PUSHJ P,ERROR1			;ERROR, CLASS ONE
;		DISK ERRORS
NOPAR:	TRNE UUO,NEWST			;WILL UCHK BE HONEST?
	TRNN UUO,UCHK			;YES, WAS THERE A UNIT CHECK?
	JRST TYPE0			;NO, CHECK TYPEOUT AND ERROR FLAGS
	POPACS
	PUSHJ P,SENSE			;DO SENSE
	CAIA				;SENSE LOST
	JRST SNSDON
	PUSHACS
	PUSHJ P,DISMES
	ASCIZ/SENSE FAILED.
/
	AOS CSTOP			;INDICATE COLD STOP
	AOS TYPANY
	PUSHJ P,ERROR1			;THIS IS CLASS 1 ERROR
	JRST TYPE0

SNSDON:	PUSHACS
	AOS SNSTYP			;INDICATE TYPEOUT OF SENSE DATA
	LDB UUO,[POINT 16,SNSDAT,15]	;GET FIRST TWO BYTES OF SENSE
	TRNN UUO,CMDRJT			;COMMAND REJECT?
	JRST NORJCT			;NO
	TRNE UUO,WRTINH			;WRITE INHIBITED?
	JRST NORJCT			;YES, CATCH IT AT CLASS 5
	LDB TAC,[POINT 8,SNSDAT+1,31]	;PICK UP BYTE 7
	CAIE TAC,DVERR			;INVALID DATA?
	CAIN TAC,DWERR			;DIAGNOSTIC WRITE ERROR?
	SKIPL ERRCMD			;IS IT REALLY US?
	CAIA				;NO, MAYBE REAL LOSSAGE
	JRST [	AOS DEATH
		AOS DSKFLG		;KILL THE BUM
		JRST NORJCT]
	PUSHJ P,ERROR0			;OTHERWISE ERROR CLASS 0
NORJCT:	TRNE UUO,BITCL0			;OTHER CLASS 0 ERROR?
	PUSHJ P,ERROR0			;ERROR, CLASS 0
	TRNE UUO,BITCL1			;BUS OUT PARITY IS
	PUSHJ P,ERROR1			;ERROR, CLASS 1
	TRNN UUO,BITEQU			;EQUIPMENT CHECK IS CLASS 1 OR 3
	JRST NOCL13
	LDB TAC,[POINT 8,SNSDAT+1,31]	;GET SENSE BYTE 7
	CAIE TAC,SKCHK			;SEEK CHECK
	CAIN TAC,SKINCP			;OR SEEK INCOMPLETE
	JRST SKCHKA			;ARE CLASS 3
	CAIN TAC,RTYABT			;COMMAND RETRY ABORTED?
	JRST [	PUSHJ P,ERROR4		;ERROR, CLASS 4
		JRST NOCL13]
	TRNE UUO,PERM			;REAL EQUIPMENT CHECK, IS IT PERMANENT?
	AOS CSTOP			;YES, COLD STOP
	PUSHJ P,ERROR1			;ALL ELSE IS CLASS 1
	JRST NOCL13

SKCHKA:	POPACS
	PUSHJ P,ERROR3
	PUSHACS
	LDB UUO,[POINT 16,SNSDAT,15]	;RELOAD UUO
NOCL13:	TRNE UUO,BITCL2			;DATA CHECK?
	PUSHJ P,ERROR2			;ERROR, CLASS 2
	TRNE UUO,BITCL4			;OVERRUN?
	PUSHJ P,ERROR4			;ERROR, CLASS 4
	TRNE UUO,BITCL5			;INT. REQ. OR WRITE LOCK?
	PUSHJ P,ERROR5			;ERROR, CLASS 5
;		ERROR/USAGE STATISTICS
	LDB TAC,[POINT 8,SNSDAT,23]	;PICK-UP BYTE 2
	TRNN TAC,ERRUSE			;ERROR-USAGE DATA?
	JRST TYPE0
	AOS DSKFLG
	PUSHJ P,DISDATE
	PUSHJ P,DISMES
	ASCIZ/3330 ERROR-USAGE STATISTICS.
/
	PUSHJ P,DRIVEP			;PRINT DRIVE ID
	PUSHJ P,DISMES
	ASCIZ/  PACK = /
	LDB TAC,[POINT 3,LSTAT,11]
	PUSHJ P,DISLOC
	PUSHJ P,DISMES
	ASCIZ/
TBYTES = /
	LDB TAC,[POINT 32,SNSDAT+2,31]	;BYTES 8-11 TOTAL BYTES
	PUSHJ P,DISDEC			;IN DECIMAL
	LDB UUO,[POINT 16,SNSDAT+3,15]	;BYTES 12-13 CORRECTABLE DATA CHECKS
	JUMPE UUO,ERRU1
	PUSHJ P,DISMES
	ASCIZ/
CDCHKS = /
	MOVE TAC,UUO
	PUSHJ P,DISDEC
ERRU1:	LDB UUO,[POINT 16,SNSDAT+3,31]	;BYTES 14-15 RETRY DATA CHECKS
	JUMPE UUO,ERRU2
	PUSHJ P,DISMES
	ASCIZ/
RDCHKS = /
	MOVE TAC,UUO
	PUSHJ P,DISDEC
ERRU2:	PUSHJ P,DISMES
	ASCIZ/
NSEEKS = /
	LDB TAC,[POINT 16,SNSDAT+4,15]	;BYTES 16-17 NUMBER OF SEEKS
	PUSHJ P,DISDEC
	LDB UUO,[POINT 8,SNSDAT+4,31]	;BYTE 19 NUMBER OF ERROR SEEKS
	JUMPE UUO,ERRU3
	PUSHJ P,DISMES
	ASCIZ/
ESEEKS = /
	MOVE TAC,UUO
	PUSHJ P,DISDEC
ERRU3:	LDB UUO,[POINT 8,SNSDAT+5,7]	;BYTE 20 COMMAND OVERRUNS
	JUMPE UUO,ERRU4
	PUSHJ P,DISMES
	ASCIZ/
COVRRN = /
	MOVE TAC,UUO
	PUSHJ P,DISDEC
ERRU4:	LDB UUO,[POINT 8,SNSDAT+5,15]	;BYTE 21 DATA OVERRUNS
	JUMPE UUO,ERRU5
	PUSHJ P,DISMES
	ASCIZ/
DOVRRN = /
	MOVE TAC,UUO
	PUSHJ P,DISDEC
ERRU5:	PUSHJ P,DISMES
	ASCIZ/


/
;		ERROR PRINT
TYPE0:	SKIPE DSKFLG
	JRST TYPE1
	AOS TYPANY
	PUSHJ P,DISMES
	ASCIZ/UNKNOWN /
TYPE1:	SKIPN TYPANY			;TYPE ANYTHING?
	JRST ERRGO			;NO, END OF TYPE CHECKING
	PUSHJ P,DISMES
	ASCIZ/DISK ERROR. /
	PUSHJ P,DISDAT
	MOVE UUO,DSKACS+DDB
	SKIPL DSKLRN			;FILE OP?
	SKIPN FILNAM(UUO)		;ANY FILE?
	JRST NOFIL			;NO, DON'T PRINT CRUD
	PUSHJ P,DISMES
	ASCIZ/FILE = /
	MOVE TAC1,FILNAM(UUO)
	PUSHJ P,DISSIX
	HLLZ TAC1,FILEXT(UUO)
	JUMPE TAC1,NOEXT
	MOVEI TEM,"."
	PUSHJ P,DISTYO
	HLLZ TAC1,FILEXT(UUO)
	PUSHJ P,DISSIX
NOEXT:	MOVEI TEM,"["
	PUSHJ P,DISTYO
	MOVE TAC1,FILPPN(UUO)
	PUSHJ P,DISSIX
	PUSHJ P,DISMES
	ASCIZ/]    /
NOFIL:	MOVE UUO,ERRCMD
	ADDI UUO,1			;OFFSET SO DIAG WORKS
	PUSHJ P,DISERR
	(UUO)[	ASCIZ/DIAG/		;-1
		ASCIZ/SEEK/
		ASCIZ/SRCH/
		ASCIZ/READ/
		ASCIZ/WRITE/]		;3
	[ASCIZ/ OP
/]
	-1
	MOVE TAC,DSKLRN
	CAMN TAC,[-1]
	JRST SATPNT
	CAMN TAC,[-2]			;THIS IS SET FOR ASYNC ERRORS
	JRST NSWAP
	PUSHJ P,DISMES
	ASCIZ/JOB = /
	HRRZ TAC,DXJ
	PUSHJ P,DISDCP
	SKIPL DXJ
	JRST NSWAP1
	PUSHJ P,DISMES
	ASCIZ/ SWAP/
NSWAP1:	PUSHJ P,DISERR
	[ASCIZ/  DXS = /]
	DISARG OCT,DXS
	[ASCIZ/  DXW = /]
	DISARG OCT,DXW
	-1
	JRST NSWAP

SATPNT:	PUSHJ P,DISMES
	ASCIZ/SAT TABLE/
NSWAP:	PUSHJ P,DISERR
	[ASCIZ/
CONI BITS = /]
	DISARG OCT,CNISAV
	[ASCIZ/
/]
	-1
	PUSHJ P,DISMES
	ASCIZ/PACK = /
	LDB TAC,[POINT 3,LSTAT,11]	;GET DEVICE ADDRESS
	PUSHJ P,DISLOC
	PUSHJ P,DISMES
	ASCIZ/  CYL = /
	LDB TAC,[POINT 16,SKDAT,31]
	PUSHJ P,DISLOC
	PUSHJ P,DISMES
	ASCIZ/  HD = /
	LDB TAC,[POINT 8,SKDAT+1,15]
	PUSHJ P,DISLOC
	PUSHJ P,DISMES
	ASCIZ/  REC = /
	LDB TAC,[POINT 8,SCDAT+1,7]
	PUSHJ P,DISLOC
	PUSHJ P,DISMES
	ASCIZ/
/
	SKIPN HAFLAG			;HOME ADDRESS TO PRINT?
	JRST NOHA
	PUSHJ P,DISMES
	ASCIZ/HA CYL = /
	LDB TAC,[POINT 16,HA,23]
	PUSHJ P,DISLOC
	PUSHJ P,DISMES
	ASCIZ/  HA HD = /
	LDB TAC,[POINT 8,HA+1,7]
	PUSHJ P,DISLOC
	PUSHJ P,DISMES
	ASCIZ/
/
NOHA:	MOVEI UUO,0			;START WITH CLASS 0
CLLOP:	SKIPN ERRCL0(UUO)		;ANY ERRORS OF THIS CLASS
	JRST NOCL			;NO
	PUSHJ P,DISERR
	[ASCIZ/C/]
	DISARG DEC,UUO
	[ASCIZ/ = /]
	DISARG DEC,ERRCL0(UUO)
	[ASCIZ/  /]
	-1
NOCL:	CAIGE UUO,4			;HIGHEST COUNTING CLASS?
	AOJA UUO,CLLOP
	SKIPN DEATH
	JRST NODIE
	PUSHJ P,DISMES
	ASCIZ/   DEATH/
NODIE:	PUSHJ P,DISMES
	ASCIZ/
/
	SKIPN SNSTYP
	JRST TYPDON			;NO SENSE DATA, GO CHECK FOR ERRORS
	PUSHJ P,DRIVEP			;PRINT DRIVE ID
	PUSHJ P,DISMES
	ASCIZ/  SENSE DATA =
/
	MOVE UUO,[POINT 8,SNSDAT]
	PUSH P,[0]
SNSLOP:	ILDB TAC,UUO
	JUMPE TAC,NULSNS
	PUSH P,TAC
	PUSHJ P,DISERR
	DISARG DEC,-2(P)
	[ASCIZ/ = /]
	DISARG LOC,-1(P)
	[ASCIZ/
/]
	-1
	POP P,(P)
NULSNS:	AOS TAC,(P)
	CAIGE TAC,SNSLEN
	JRST SNSLOP
	POP P,(P)
TYPDON:	PUSHJ P,DISMES
	ASCIZ/


/
ERRGO:	SKIPN CSTOP
	JRST NOSTOP
	PUSHJ P,DISMES
	ASCIZ/DO SOMETHING ABOUT IT, THEN PUSH CONTINUE.


/
	SETOM DISFLAG
	PUSHJ P,DISFLUSH
	HALT .+1
NOSTOP:	POPACS
	PUSHJ P,BLAST		;MAKE SURE ERROR GOES AWAY!
	SKIPN DEATH
	POPJ P,			;DIDN'T DIE, TRY AGAIN RETURN
	MOVE TAC1,DSKACS+DDB		;GET DDB ADDRESS
	MOVEI AC3,IODERR	;START WITH DEVICE ERROR
	MOVE TAC,ERRCL2		;GET DATA ERROR COUNT
	CAML TAC,MAXCL2		;OVER MAX LIMIT?
	TRO AC3,IODTER		;YES, GIVE DATA ERROR ALSO
	IORM AC3,DEVIOS(TAC1)
	JRST CPOPJ1		;GIVE ERROR RETURN

DRIVEP:	PUSHJ P,DISMES
	ASCIZ/DRIVE /
	LDB TEM,[POINT 6,SNSDAT+1,7]
	JUMPN TEM,ISKNWN	;UNKNOWN?
	PUSHJ P,DISMES		;YES
	ASCIZ/UNKNOWN/
	POPJ P,

ISKNWN:	ANDI TEM,7			;JUST THE IMPORTANT BITS
	ADDI TEM,"A"
	JRST DISTYO
;ERROR CLASS DESCRIPTIONS
;CLASS 0:		       BYTE    BIT
;	INVALID TRACK FORMAT	1	1
;	END OF CYLINDER		1	2
;	NO RECORD FOUND		1	4
;	FILE MASK VIOLATION	1	5
;	OPERATION INCOMPLETE	1	7
;	TOO MANY LOSING SEARCHES
;	DATA CHAIN ERROR (CHANNEL CONI)
;	ATTENTION (STATUS BYTE)
;	BUSY (STATUS BYTE)
;	UNIT EXCEPTION (STATUS BYTE)
;	COMMAND REJECT		0	0
;		AND NOT:
;			WRITE INHIBITED
;			DIAG LOAD INVALID DATA
;			DIAG WRITE ERROR

;CLASS 1:
;	BUS OUT PARITY		BYTE 0 BIT 2
;	SELECT ERROR (CHANNEL CONI)
;	NXM (CHANNEL CONI)
;	PARITY ERROR (CHANNEL CONI, CORE TO DISK)
;	SENSE FAILED (ERROR ON SENSE AFTER UNIT CHECK)
;	EQUIPMENT CHECK		BYTE 0 BIT 3
;		AND NOT:
;			SEEK CHECK
;			RETRY ABORTED

;CLASS 2:
;	DATA CHECK		BYTE 0 BIT 4

;CLASS 3:
;	SEEK CHECK		BYTE 0 BIT 3  BYTE 7 = 32 OR 33 (OCTAL)

;CLASS 4:
;	OVERRUN			BYTE 0 BIT 5
;	RETRY ABORTED		BYTE 0 BIT 3  BYTE 7 = 6
;ERROR CLASS HANDLERS
ERROR0:	TDZA TAC1,TAC1		;CLASS 0
ERROR1:	MOVEI TAC1,1		;CLASS 1
ERRORX:	AOS DSKFLG		;INDICATE ERROR SEEN
	AOS TOTCL0(TAC1)
	AOS TAC,ERRCL0(TAC1)
	CAMGE TAC,MAXCL0(TAC1)	;TOO MANY?
	JRST TYTST
	AOS DEATH
	JRST TYPIT

TYTST:	TDNE TAC,TYMSK0(TAC1)	;SHOULD WE TYPE THIS ONE?
	SKIPE TYPCL0(TAC1)	;OR MAYBE ALL OF THEM?
TYPIT:	AOS TYPANY		;TYPE OUT
	POPJ P,

ERROR2:	AOS DSKFLG
	AOS TOTCL2
	AOS TAC,ERRCL2
	CAML TAC,MAXCL2
	JRST TBAD
	MOVEI TAC1,2		;CLASS 2
	JRST TYTST

TBAD:	AOS DEATH
	AOS TYPANY
	JRST	MRKBAD		;JUMP TO DSKSER TO MARK A BAD TRACK

ERROR3:	MOVEI TAC1,3		;CLASS 3
	PUSHJ P,ERRORX		;COUNT AND TEST DEATH AND TYPING
	SETZM ERRHA		;NOW SETUP FOR READ HA AND RECAL.
	SETZM ERRRCL
REHA:	PUSHJ P,BLAST		;CLEAR CHANNEL FOR READ HA
	CONO IBM,CNEWST!CLREND!ACTCLR
	CONO PMP,NEWST!UNEND!10!DSKCHN
	DATAO PMP,[HA]
	DATAO IBM,RDHACM
	PUSHJ P,ISYNC
	JRST REHA
	CAIA
	JRST DORCLA
	CONO IBM,2
	AOS TAC,ERRHA
	CAMGE TAC,MAXHA
	JRST REHA
	AOS TYPANY
	AOS CSTOP
	PUSHACS
	PUSHJ P,DISMES
	ASCIZ/READ HOME ADDRESS LOST!
/
	POPACS
	POPJ P,

DORCLA:	SETOM HAFLAG
DORCL:	PUSHJ P,BLAST
	CONO IBM,CNEWST!CLREND!ACTCLR
	CONO PMP,NEWST!UNEND!10!DSKCHN
	DATAO IBM,RCALCM
	PUSHJ P,ISYNC
	JRST DORCL
	JRST ERRCAL
	MOVE TAC,PMPCNI
	TRNE TAC,DEVEND			;DEVICE END YET?
	POPJ P,				;YES, DONE
	CONO IBM,ACTCLR			;GO AWAY
	PUSHJ P,ISYNC
	JRST DORCL
	JRST ERRCAL
	MOVE TAC,PMPCNI
	TRNE TAC,DEVEND			;BETTER HAVE IT NOW
	POPJ P,
ERRCAL:	CONO IBM,2
	AOS TAC,ERRRCL
	CAMGE TAC,MAXRCL
	JRST DORCL
	AOS TYPANY
	AOS CSTOP
	PUSHACS
	PUSHJ P,DISMES
	ASCIZ/RECALIBRATE FAILED!
/
	POPACS
	POPJ P,

ERROR4:	MOVEI TAC1,4
	JRST ERRORX

ERROR5:	AOS DSKFLG
	LDB TAC,[POINT 3,LSTAT,11]
	CAIG TAC,FPACKS-1
	JRST SYSLOS
	AOS DEATH			;ERROR BIT TO LOSER!!!!
	MOVEI TAC,IOIMPM		;USE IMPROPER MODE BIT TO INDICATE OFF LINE OR WRITE LOCK
	MOVE TAC1,DSKACS+DDB
	IORM TAC,DEVIOS(TAC1)
	POPJ P,

SYSLOS:	TRNN UUO,WRTINH			;WRITE INHIBITED?
	JRST SYSLOX			;NO, MUST BE OFF LINE
	PUSHJ P,DISMES
	ASCIZ/PACK IN WRITE LOCK!
/
SYSLOZ:	AOS TYPANY
	AOS CSTOP
	POPJ P,

SYSLOX:	LDB TAC,[POINT 6,SNSDAT+1,7]	;DRIVE ID
	JUMPE TAC,SYSLOY
	PUSHJ P,DISMES
	ASCIZ/DRIVE NOT READY!
/
	JRST SYSLOZ

SYSLOY:	PUSHJ P,DISMES
	ASCIZ/ID PLUG NOT INSTALLED!
/
	JRST SYSLOZ

SENSE:	SETZM ERRSNS
SENSE1:	PUSHJ P,BLAST
	CONO IBM,CNEWST!CLREND!ACTCLR
	CONO PMP,NEWST!UNEND!10!DSKCHN
	DATAO PMP,SNWCMA
	DATAO IBM,SNSCMD
	PUSHJ P,ISYNC
	JRST SENSE1
	CAIA
	JRST CPOPJ1
	AOS TAC,ERRSNS
	CAML TAC,MAXSNS		;TOO MANY?
	POPJ P,			;LOSE BIG
	JRST SENSE1

BLAST:	MOVEI TAC,10000
	CONSO PMP,IDLE		;TRY TO WAIT FOR PMP TO BECOME IDLE!
	SOJG TAC,.-1
	CONO IBM,CRESET!CNEWST!CLREND!ACTCLR	;NOW RESET CHANNEL
	MOVEI TAC,1000		;LET HIM COOL OFF
	SOJG TAC,.
	POPJ P,			;LET'S HOPE THAT'S ENOUGH
;HIGH PRIORITY INTERRUPT CODE (HPIC)
	JSR 0,D2X			;DUMMY FOR FUNNY ERRORS
↑D2IGO:	DATAO PMP,SKWCMA		;ISSUE SEEK COMMAND
	DATAO IBM,SKCMD
SKSRCH:	MOVNI TAC,RCPBLK*3
	MOVEM TAC,CT			;INITIALIZE LOSING SEARCH COUNT
	SETOM LSTREC			;NO BACKUP FROM HERE
	DATAO PMP,SCWCMA
	DATAO IBM,SCCMD
	JSR 0,D2X
DOCMD:	DATAO PMP,XWCMA
	DATAO IBM,XCMD
	JSR 1,D2X
	TRNN TAC,STMOD			;SUCCESSFUL SEARCH?
	JRST RESRCH			;NO
	AOS WCT				;INC WINNING SEARCHES
READDN:					;ENTER HERE FROM READ AFTER READ
	LDB TAC,[POINT 8,SCDAT+1,7]	;GET LAST RECORD NUMBER
	MOVE TAC,RCLTAB(TAC)		;GET WCMA INCREMENT FOR THIS RECORD.
	ADD TAC,XWCMA			;INC WCMA
	XCT ENDTST			;CHECK FOR WC COUNTED OUT
	JRST D2FIN			;IT'S OUT. WE'RE DONE
	MOVEM TAC,XWCMA			;ONLY AFTER IT'S NOT THE END, STORE XWCMA
	MOVE TAC,SCDAT+1		;GET RECORD NUMBER FROM SEARCH COMMAND
	MOVEM TAC,LSTREC		;LAST SUCCESSFUL RECORD
	MOVSI TAC,(<BYTE(8)1>)
	ADDB TAC,SCDAT+1		;INCREMENT RECORD NUMBER FOR SEARCH
	CAMG TAC,[BYTE(8)RCPTRK-1]	;TRACK OVERFLOW?
	JRST READON			;SAME TRACK. CHAIN TO READ OF NEXT RECORD
	SKIPL DSKLRN
	JRST D2EOD			;FILE SYSTEM - NOT ALLOWED TO WRAP AROUND
	MOVE TAC,XWRAP			;THIS IS RECORD TO WRAP TO (SET UP AT CADDR)
	MOVEM TAC,SCDAT+1
	MOVE TAC,[BYTE(16)1]		;PREPARE TO INC HEAD BY 1
	ADDB TAC,SKDAT+1
	CAMG TAC,[BYTE(16)TRKCYL-1]	;OVERFLOW CYLINDER?
	JRST SKOK			;NO, START SEEK
	MOVEI TAC,1⊗4			;INC CYLINDER ADDRESS
	ADDM TAC,SKDAT
	SETZM SKDAT+1			;WRAP TO HEAD 0
	LDB TAC,[POINT 3,SKCMD,21]	;PACK NUMBER
	MOVE TAC,NCYLSH(TAC)		;<NUMBER CYLS THIS PACK>⊗4
	CAMG TAC,SKDAT			;OFF END OF PACK?
	JRST D2EOD			;YES, ALWAYS ERROR
SKOK:	HLRZ TAC,SKDAT+1
	LSH TAC,4
	HRL TAC,SKDAT
	LSH TAC,-2
	MOVEM TAC,SCDAT			;SET UP SCDAT FROM CYL IN SKDAT AND HD IN +1
	DATAO PMP,SKWCMA
	DATAO IBM,SKCMD
	JSR 2,D2X
	JRST SKSRCH
;MORE HPIC
D2EOD:	SETOM D2LUZ
D2FIN:	DATAO IBM,NOPCMD
	JSR 2,D2X
	SETOM D2DONE		;FLAG OP COMPLETE TO DSKCHN
LSRCH:	CONO PMP,NEWST!UNEND!10!DSKCHN
	JSR 2,D2X
	JRST D2BARF

RESRCH:	DATAO IBM,NOPCMD	;SEND NOOP TO STOP CHAINING AFTER FAILING SEARCH
	AOS LCT
	AOSL CT
	JRST LSRCH		;TOO MANY LOSING SEARCHES!
	DATAO PMP,SCWCMA
	DATAO IBM,SCCMD
	JSR 1,D2X		;LAST OP WAS SEARCH
	SETOM LSTREC		;RETRYING SEARCH, NO BACKUP
	JRST DOCMD

;OLD CODE, DO SEARCH AFTER WRITE
SRCLUP:	MOVNI TAC,RCPBLK*3
	MOVEM TAC,CT
	DATAO PMP,SCWCMA
	DATAO IBM,SCCMD
	JSR 2,D2X		;LAST OP WAS WRITE
	SETOM LSTREC		;READ DONE, NO BACKUP
	JRST DOCMD

;NEW CODE, CHAIN READ FROM READ
READON:	MOVE TAC,XCMD		;READ OR WRITE?
	TRNE TAC,1
	JRST SRCLUP		;WRITE. MUST ALWAYS CHAIN WRITE FROM SEARCH
	DATAO PMP,XWCMA		;BUT, READ CAN BE CHAINED FROM READ
	DATAO IBM,XCMD
	JSR 2,D2X		;LAST OP WAS READ
	SETOM LSTREC		;READ DONE, NO BACKUP
	JRST READDN		;LEAP IN HERE

;TABLE OF WCMA INCREMENTS CORRESPONDING TO EACH RECORD OF A TRACK.
RCLTAB:
REPEAT BKPTRK,<
	SECSIZ,,SECSIZ
REPEAT RCPBLK,<
	RECSIZ,,RECSIZ
>
>

BEND DSKINT

↑IXINT←IXINT

BEND DSKSER